<?php
namespace Admin\Controller;
use Think\Controller;
class CommonController extends Controller 
{
    /**
    *自动执行    简单登陆权限  验证
    */
    public function _initialize()
    {
        
        $path = CONTROLLER_NAME.'/';
        if (in_array($path, C('ADMIN_AUTH_PATH'))) {
            //判断登陆否
            if (!$_SESSION['username']) {

                $this->error('非法访问 跳转中...',U('admin/login/index'));
            }
            //浏览记录 记录入库
            $this->admin_history(); 
        }else {
            //浏览记录 记录入库
            $this->admin_history(); 
        }
    }

    /**
    *纪录所有历史浏览记录
    *$url [REQUEST_URI] => /fly/index.php/admin/level/index.html 
    *$ip = get_client_ip();
    *
    */
    public function admin_history()
    {
      $data['username'] = $_SESSION['username']?$_SESSION['username']:'非法登陆者';
      $data['client_ip'] = get_client_ip();
      $data['url'] = $_SERVER['REQUEST_URI'];
      $data['access_time'] = time();
      //入库
      M('admin_history')->add($data);
    }





    
}